package impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
import datautil.DemoDateBaseUtil;

public class UserDao {
	
	 public static void select() throws SQLException{
		 Connection conn = DemoDateBaseUtil.getConnection();
		 String sql ="select * from exam";
		 PreparedStatement ps=conn.prepareStatement(sql);
		 ResultSet rs=ps.executeQuery(sql);
		 System.out.print("请输入题号:");
		 Scanner sc=new Scanner(System.in);
	      	String id=sc.next();
	      	System.out.print("请输入答案:");
	      //	Scanner sc1=new Scanner(System.in);
	      	String answer=sc.next();
		 while (rs.next()) {
		   
		      	if (rs.getString("id").equals(id)) {
					if(rs.getString("answer").equals(answer)){
						
					    System.out.println("答案正确"+" 此题得分为："+rs.getString("score"));
					}
					else {
						System.out.println("答案错误,"+" 正确答案应该为:"+rs.getString("answer")+" 此题得分为："+0);
						
						//如果上面的多选错误，则用下面的输入，进行判断，再得分
						Scanner sc1=new Scanner(System.in);
						 System.out.print("请输入题号:");
						String id1=sc.next();
						 System.out.print("请输入答案:");
				      	String str=sc.next();
					   String str1="ABCD";
					  if(str1.indexOf(str1)!=-1){
					   System.out.println("包含此答案"+" 此题得分为："+1);
					  }else{
					   System.out.println("不包含此答案");
					  }
					}
				}
			 
			 }
		 

	}
}